n, m = map(int, input().split())
dp = [list(map(int, input().split())) for _ in range(n)]
dir = [(0, 1), (0, 2), (0, 3), (1, 0), (1, 1), (1, 2), (2, 0), (2, 1), (3, 0)]
# 从重点开始反推，当计算 dp[x][y] 时，
# 所有满足 nx ≤ x 且 ny ≤ y 的前驱点 (nx, ny) 已经被计算过了
for x in range(n):
    for y in range(m):
        res = []
        for i, j in dir:
            # 往左上方倒推
            nx, ny = x - i, y - j
            if 0 <= nx < n and 0 <= ny < m:
                res.append(dp[nx][ny])
        dp[x][y] += max(res) if len(res) != 0 else 0
print(dp[-1][-1])

# DFS解法
# n, m = map(int, input().split())
# grid = [list(map(int, input().split())) for _ in range(n)]
# dirs = [(0,1),(0,2),(0,3),(1,0),(1,1),(1,2),(2,0),(2,1),(3,0)]
#
# # 记忆化数组，初始化为 None 表示未计算
# memo = [[None]*m for _ in range(n)]
#
# def dfs(x, y):
#     if x == n-1 and y == m-1:
#         return grid[x][y]
#     if memo[x][y] is not None:
#         return memo[x][y]
#
#     max_val = -float('inf')
#     for dx, dy in dirs:
#         nx, ny = x + dx, y + dy
#         if 0 <= nx < n and 0 <= ny < m:
#             if nx >= x and ny >= y:  # 确保不回头
#                 max_val = max(max_val, dfs(nx, ny))
#
#     memo[x][y] = grid[x][y] + (max_val if max_val != -float('inf') else 0)
#     return memo[x][y]
#
# print(dfs(0, 0))
